import { HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { RequestService } from './request.service';
import { ProductListItem, ProductSamplyListItem, Product } from '../model/product';
import { PaginationList } from '../model/message';
import { Observable } from 'rxjs';


@Injectable()
export class ProductApiService {

  constructor(
    private request: RequestService,
  ) { }

  public fetchList(params: HttpParams): Observable<PaginationList<ProductListItem>> {
    const url = '/product/list';
    return this.request.get<PaginationList<ProductListItem>>(url, params)
  }

  public fetchSimpleList(params: HttpParams): Observable<PaginationList<ProductSamplyListItem>> {
    const url = '/product/simpleList';
    return this.request.get<PaginationList<ProductSamplyListItem>>(url, params);
  }

  public updateDeleteStatus(params: HttpParams): Observable<any> {
    const url = '/product/update/deleteStatus';
    return this.request.post(url, null, params);
  }

  public updateNewStatus(params: HttpParams): Observable<any> {
    const url = '/product/update/newStatus';
    return this.request.post(url, null, params);
  }

  public updateRecommendStatus(params: HttpParams): Observable<any> {
    const url = '/product/update/recommendStatus';
    return this.request.post(url, null, params);
  }

  public updatePublishStatus(params: HttpParams): Observable<any> {
    const url = '/product/update/publishStatus';
    return this.request.post(url, null, params);
  }

  public creatProduct(data: Product): Observable<any> {
    const url = '/product/create';
    return this.request.post(url, data);
  }

  public updateProduct(id: number, data: Product): Observable<any> {
    const url = '/product/update/' + id;
    return this.request.post(url, data);
  }

  public getProduct(id: number): Observable<Product> {
    const url = '/product/updateInfo/' + id;
    return this.request.get<Product>(url);
  }
}
